package com.gaogzhen.threadLocal;

/**
 * @author Administrator
 * @version 1.0
 * @description 账户类
 * @date 2022-10-15 11:19
 */
public class Account {
    private int money;

    public Account(int money) {
        this.money = money;
    }

    public int getMoney() {
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }

    /**
     * 转账
     * @param a         转入账户
     * @param amount    转入金额
     */
    public void transfer(Account a, int amount) {
        // 判断当前金额是否大于等于转账金额
        if (money >= amount) {
            // 当前账户减去转账金额
            money -= amount;
            // 转入账户加上转账金额
            a.setMoney(a.getMoney() + amount);
        }
    }
}
